package com.ltmall.api.controller;

import com.ltmall.api.bean.*;
import com.ltmall.api.comm.Path;
import com.ltmall.api.entity.*;
import com.ltmall.api.manager.AccountManager;
import com.ltmall.api.manager.SubUnderwritingManager;
import com.ltmall.api.refund.wx.bean.WX;
import com.ltmall.api.util.ImgUtil;
import com.ltmall.api.util.PageUtil;
import com.ltmall.api.util.RemoteUtil;
import com.ltmall.api.util.UUIDGenerator;
import com.ltmall.api.weixin.pay.utils.WechatRedPackUtils;
import com.ltmall.api.weixin.pay.utils.WeixinUtils;
import com.ltmall.api.weixin.util.Constant;
import com.ltmall.api.weixin.util.QRCodeUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import sun.misc.BASE64Decoder;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileOutputStream;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
public class SubUnderwritingController {

    boolean opTag, valiTag;

    private SubUnderwritingManager subUnderwritingManager;
    private AccountManager accountManager;

    private Logger logger = LogManager.getLogger(SubUnderwritingController.class);

    public SubUnderwritingManager getSubUnderwritingManager() {
        return subUnderwritingManager;
    }

    public void setSubUnderwritingManager(SubUnderwritingManager subUnderwritingManager) {
        this.subUnderwritingManager = subUnderwritingManager;
    }

    public AccountManager getAccountManager() {
        return accountManager;
    }

    public void setAccountManager(AccountManager accountManager) {
        this.accountManager = accountManager;
    }

    public void subUnderwriterRegisterNecessary(HttpServletRequest request,
                                                HttpServletResponse response) {
        String userId = request.getParameter("userID");
        String userToken = request.getParameter("userToken");
        valiTag = accountManager.validate(Integer.parseInt(userId), userToken);
        if (!valiTag) {
            RemoteUtil.response(response, null, -100, "身份异常");
            return;
        }

        ThJsonSubUnderwriterRegisterNecessary necessary = subUnderwritingManager
                .subUnderwriterRegisterNecessary(Integer.parseInt(userId));
        if (necessary != null) {
            RemoteUtil.response(response, necessary, 1, "操作成功");
        } else {
            RemoteUtil.response(response, null, -1, "操作失败");
        }
    }

    public void subUnderwriterRegister(HttpServletRequest request, HttpServletResponse response) {
        String userId = request.getParameter("userID");
        String userToken = request.getParameter("userToken");
        valiTag = accountManager.validate(Integer.parseInt(userId), userToken);
        if (!valiTag) {
            RemoteUtil.response(response, null, -100, "身份异常");
            return;
        }
        //关闭注册会员入口
        /*opTag = subUnderwritingManager.subUnderwriterAdd(Integer.parseInt(userId));*/
        if (opTag) {
            RemoteUtil.response(response, null, 1, "操作成功");
        } else {
            RemoteUtil.response(response, null, -1, "操作失败");
        }
    }

    /**
     * 获取用户粉丝总数
     *
     * @param request
     * @param response
     */
    public void getFansCount(HttpServletRequest request, HttpServletResponse response) {

        String userId = request.getParameter("userID");

        int fansCount = subUnderwritingManager.subUnderwriterFansCount(Integer
                .parseInt(userId));

        RemoteUtil.response(response, fansCount, 1, "操作成功");
    }

    public void subUnderwriterInfo(HttpServletRequest request, HttpServletResponse response) {
        String userId = request.getParameter("userID");
        //		String userToken = request.getParameter("userToken");
        //		valiTag = accountManager.validate(Integer.parseInt(userId), userToken);
        //		if (!valiTag) {
        //			RemoteUtil.response(response, null, -100, "身份异常");
        //			return;
        //		}

        ThJsonSubUnderwriter info = subUnderwritingManager.subUnderwriterInfoGet(Integer
                .parseInt(userId));
        if (info != null) {
            RemoteUtil.response(response, info, 1, "操作成功");
            return;
        }

        RemoteUtil.response(response, null, 1002, "可申请分销资格");

    }

    public void subUnderwriterFansList(HttpServletRequest request, HttpServletResponse response) {
        String userId = request.getParameter("userID");
        String userToken = request.getParameter("userToken");
        valiTag = accountManager.validate(Integer.parseInt(userId), userToken);
        if (!valiTag) {
            RemoteUtil.response(response, null, -100, "身份异常");
            return;
        }

        String pageStr = request.getParameter("page");
        PageUtil page = new PageUtil(Integer.parseInt(pageStr));

        List<ThJsonSubUnderwriterFans> list = subUnderwritingManager.subUnderwriterFansList(
                Integer.parseInt(userId), page);
        if (list != null) {
            RemoteUtil.response(response, list, 1, "操作成功");
        } else {
            RemoteUtil.response(response, null, -1, "操作失败");
        }
    }

    public void subUnderwritingOrderList(HttpServletRequest request, HttpServletResponse response) {
        String userId = request.getParameter("userID");
        String userToken = request.getParameter("userToken");
        valiTag = accountManager.validate(Integer.parseInt(userId), userToken);
        if (!valiTag) {
            RemoteUtil.response(response, null, -100, "身份异常");
            return;
        }

        String pageStr = request.getParameter("page");
        PageUtil page = new PageUtil(Integer.parseInt(pageStr));

        String fansName = request.getParameter("fansName");

        List<ThJsonSubUnderwriterOrder> list = subUnderwritingManager.subUnderwritingOrderList(
                Integer.parseInt(userId), fansName, page);
        if (list != null) {
            RemoteUtil.response(response, list, 1, "操作成功");
        } else {
            RemoteUtil.response(response, null, -1, "操作失败");
        }
    }

    public void subUnderwriterFansLevelUpIncomeList(HttpServletRequest request,
                                                    HttpServletResponse response) {
        String userId = request.getParameter("userID");
        String userToken = request.getParameter("userToken");
        valiTag = accountManager.validate(Integer.parseInt(userId), userToken);
        if (!valiTag) {
            RemoteUtil.response(response, null, -100, "身份异常");
            return;
        }

        String pageStr = request.getParameter("page");
        PageUtil page = new PageUtil(Integer.parseInt(pageStr));

        List<ThJsonFansLevelUpIncome> list = subUnderwritingManager
                .subUnderwriterFansLevelUpIncomeList(Integer.parseInt(userId), page);
        if (list != null) {
            RemoteUtil.response(response, list, 1, "操作成功");
        } else {
            RemoteUtil.response(response, null, -1, "操作失败");
        }
    }

    public void subUnderwriterQRCodeInfo(HttpServletRequest request, HttpServletResponse response) {
        String userId = request.getParameter("userID");
        String userToken = request.getParameter("userToken");
        valiTag = accountManager.validate(Integer.parseInt(userId), userToken);
        if (!valiTag) {
            RemoteUtil.response(response, null, -100, "身份异常");
            return;
        }

        ThJsonSubUnderwriterQRCodeInfo info = subUnderwritingManager
                .subUnderwriterQRCodeInfoGet(Integer.parseInt(userId));
        if (info != null) {
            RemoteUtil.response(response, info, 1, "操作成功");
        } else {
            RemoteUtil.response(response, null, -1, "操作失败");
        }
    }

    @SuppressWarnings("restriction")
    public void subUnderwriterQRCodeImage(HttpServletRequest request, HttpServletResponse response) {
        String userId = request.getParameter("userID");
        String userToken = request.getParameter("userToken");
        valiTag = accountManager.validate(Integer.parseInt(userId), userToken);
        if (!valiTag) {
            RemoteUtil.response(response, null, -100, "身份异常");
            return;
        }

        String imageName = null;
        try {
            String qrCodeImageBase64 = request.getParameter("qrCodeImage");
            if (qrCodeImageBase64 != null) {
                String generateFileName = UUIDGenerator.getUUID32();
                String project = Path.project;// 项目
                String dir = Path.PLATFORM + File.separator + Path.SUBUNDERWRITING;// 路径

                imageName = generateFileName + ".jpeg";
                File file = ImgUtil.creatFolder(project, dir, imageName);
                String filePath = file.getAbsolutePath();

                BASE64Decoder d = new BASE64Decoder();
                byte[] bs = d.decodeBuffer(qrCodeImageBase64);
                FileOutputStream os = new FileOutputStream(filePath);
                os.write(bs);
                os.close();
            }
        } catch (Exception e) {
            logger.error("subUnderwriterQRCodeImage e: " + e);
            RemoteUtil.response(response, null, -1, "操作失败");
            return;
        }

        opTag = subUnderwritingManager.subUnderwriterQRCodeImageUpdate(Integer.parseInt(userId),
                imageName);
        if (opTag) {
            String path = Path.nginx_server_dir_platform + Path.SUBUNDERWRITING + File.separator
                    + imageName;
            RemoteUtil.response(response, path, 1, "操作成功");
        } else {
            RemoteUtil.response(response, null, -1, "操作失败");
        }
    }

    public void subUnderwritingOutcomeList(HttpServletRequest request, HttpServletResponse response) {
        String userId = request.getParameter("userID");
        String userToken = request.getParameter("userToken");
        valiTag = accountManager.validate(Integer.parseInt(userId), userToken);
        if (!valiTag) {
            RemoteUtil.response(response, null, -100, "身份异常");
            return;
        }

        String pageStr = request.getParameter("page");
        PageUtil page = new PageUtil(Integer.parseInt(pageStr));

        List<ThSubUnderwritingOutcomes> list = subUnderwritingManager.subUnderwritingOutcomeList(
                Integer.parseInt(userId), page);
        if (list != null) {
            RemoteUtil.response(response, list, 1, "操作成功");
        } else {
            RemoteUtil.response(response, null, -1, "操作失败");
        }

    }

    public void subUnderwriterWechatRedPackGet(HttpServletRequest request,
                                               HttpServletResponse response) {
        String userId = request.getParameter("userID");
        String userToken = request.getParameter("userToken");
        valiTag = accountManager.validate(Integer.parseInt(userId), userToken);
        if (!valiTag) {
            RemoteUtil.response(response, null, -100, "身份异常");
            return;
        }

        String amountStr = request.getParameter("amount");
        BigDecimal amount = new BigDecimal(amountStr);
        amount = amount.setScale(2, BigDecimal.ROUND_HALF_UP);

        ThClientPlatforms plat = accountManager.getClientPlatformByUserId(Integer.parseInt(userId));
        if (plat == null) {
            RemoteUtil.response(response, null, -1, "操作失败，用户不存在");
            return;
        }

        if (amount.compareTo(BigDecimal.valueOf(200)) == 1) {
            RemoteUtil.response(response, null, -1, "操作失败，超过了200元");
            return;
        }

        ThSubUnderwriters subUnderwriters = subUnderwritingManager.subUnderwriterGet(Integer
                .parseInt(userId));
        if (amount.compareTo(subUnderwriters.getTotalIncome().subtract(
                subUnderwriters.getTotalOutcome())) == 1) {
            RemoteUtil.response(response, null, -1, "操作失败，超过了最大取现额度");
            return;
        }

        ThRedPackOutcomes redPack = new ThRedPackOutcomes();
        redPack.setAmount(amount);
        redPack.setState(0);
        redPack.setUserId(Integer.parseInt(userId));
        redPack.setMchBillno(WeixinUtils.getMchBillno());

        opTag = subUnderwritingManager.wechatRedPackOutcomeAdd(redPack);
        if (!opTag) {
            RemoteUtil.response(response, null, -1, "操作失败，插入红包订单失败");
            return;
        }

        WX wx = WechatRedPackUtils.sendRedPack(redPack.getMchBillno(), plat.getOpenId(), amount
                .multiply(BigDecimal.valueOf(100)).intValue());
        if (wx != null) {
            if (wx.getReturn_code().equals("SUCCESS") && wx.getResult_code().equals("SUCCESS")) {
                subUnderwriters.setTotalOutcome(subUnderwriters.getTotalOutcome().add(amount));
                subUnderwritingManager.subUnderwriterUpdate(subUnderwriters);

                redPack.setState(1);
                redPack.setSendListid(wx.getSend_listid());
                subUnderwritingManager.wechatRedPackOutcomeUpdate(redPack);

                subUnderwritingManager.subUnderwritingOutcomeAdd(Integer.parseInt(userId), amount,
                        2, redPack.getId(), 1);

                RemoteUtil.response(response, null, 1, "操作成功");
            }
        }

        RemoteUtil.response(response, null, -1, "操作失败");
        logger.error("发放红包失败。" + "return_msg:" + wx.getReturn_msg() + "err_code:"
                + wx.getErr_code() + "err_code_des" + wx.getErr_code_des());
        logger.error(wx);
    }

    public void rewardMonthly(HttpServletRequest request, HttpServletResponse response) {
        String userID = request.getParameter("userID");
        if (userID != null && userID != "") {
            /* 分别找到几个级别的粉丝数 */
            int levelGoldMedalCount = subUnderwritingManager.fansCountGetByLevelId(1,
                    Integer.parseInt(userID));
            int levelDiamondsCount = subUnderwritingManager.fansCountGetByLevelId(2,
                    Integer.parseInt(userID));
            int levelCrownCount = subUnderwritingManager.fansCountGetByLevelId(3,
                    Integer.parseInt(userID));

            System.out.println("三个等级的粉丝数量为：" + levelGoldMedalCount + "，" + levelDiamondsCount + "，"
                    + levelCrownCount);

            /* 每个级别粉丝数找到后，分别计算可得到的月奖励 */
            int levelGoldMedalReward = levelGoldMedalCount >= 10 ? 50 : 0;
            int levelDiamondsReward = levelDiamondsCount >= 10 ? 200 : 0;
            int levelCrownReward = levelCrownCount >= 10 ? 500 : 0;

            System.out.println("三个等级可获得奖励为：" + levelGoldMedalReward + "，" + levelDiamondsReward
                    + "，" + levelCrownReward);

            // 组装
            JsonReward reward = new JsonReward();
            reward.setGoldMedalCount(levelGoldMedalCount);
            reward.setGoldMedalReward(levelGoldMedalReward);
            reward.setDiamondsCount(levelDiamondsCount);
            reward.setDiamondsReward(levelDiamondsReward);
            reward.setCrownCount(levelCrownCount);
            reward.setCrownReward(levelCrownReward);

            RemoteUtil.response(response, reward, 1, "操作成功");
        } else {
            RemoteUtil.response(response, null, 400, "参数缺失");
        }
    }

    public void rewardForRecommend(HttpServletRequest request, HttpServletResponse response) {
        String userID = request.getParameter("userID");
        String pageNumber = request.getParameter("page");
        if (userID != null && userID != "" && pageNumber != null && pageNumber != "") {
            PageUtil page = new PageUtil(Integer.parseInt(pageNumber));
            System.out.println(userID + "," + pageNumber);
            List<?> clientInfoList = subUnderwritingManager.rewardGotFansInfoGetByUserId(
                    Integer.parseInt(userID), page);
            if (clientInfoList != null && clientInfoList.size() > 0) {
                List<JsonRewardAndFans> list = new ArrayList<JsonRewardAndFans>();
                for (int i = 0; i < clientInfoList.size(); i++) {
                    Object[] obj = (Object[]) clientInfoList.get(i);
                    int level = Integer.parseInt(obj[2].toString());
                    String name = "";
                    String avatar = "";
                    int userId = Integer.parseInt(obj[3].toString());
                    // 根据等级计算奖励
                    int rewards = 0;
                    if (level == 1) {
                        rewards = 10;
                    } else if (level == 2) {
                        rewards = 60;
                    } else if (level == 3) {
                        rewards = 200;
                    }
                    if (obj[0] != null && obj[0] != "") {
                        avatar = obj[0].toString();
                    }
                    if (obj[1] != null && obj[1] != "") {
                        name = obj[1].toString();
                    }
                    //					logger.info(" 粉丝：" + obj[1].toString() + "，等级：" + level + "贡献奖励：" + rewards + "元。");
                    JsonRewardAndFans rewardFans = new JsonRewardAndFans();
                    rewardFans.setIcon(avatar);
                    rewardFans.setUserName(name);
                    rewardFans.setReward(rewards);
                    rewardFans.setLevelID(level);
                    rewardFans.setUserID(userId);
                    list.add(rewardFans);
                }
                RemoteUtil.response(response, list, 1, "操作成功");
            } else {
                RemoteUtil.response(response, null, 410, "没有记录");
            }
        } else {
            RemoteUtil.response(response, null, 400, "参数缺失");
        }
    }

    public void fansLevelUpIncomeHistoryStatistics(HttpServletRequest request,
                                                   HttpServletResponse response) {
        String userId = request.getParameter("userID");
        String userToken = request.getParameter("userToken");
        valiTag = accountManager.validate(Integer.parseInt(userId), userToken);
        if (!valiTag) {
            RemoteUtil.response(response, null, -100, "身份异常");
            return;
        }

        String year = request.getParameter("year");
        String month = request.getParameter("month");

        Calendar calendar = Calendar.getInstance();
        calendar.set(Integer.parseInt(year), Integer.parseInt(month) - 1, 1, 0, 0, 0);
        calendar.add(Calendar.MONTH, 1);
        Date startTime = calendar.getTime();

        calendar.add(Calendar.MONTH, 1);
        calendar.add(Calendar.SECOND, -1);
        Date endTime = calendar.getTime();

        int levelGoldMedalCount = subUnderwritingManager.myFansCountGetByMonth(1,
                Integer.parseInt(userId), startTime, endTime);
        int levelDiamondsCount = subUnderwritingManager.myFansCountGetByMonth(2,
                Integer.parseInt(userId), startTime, endTime);
        int levelCrownCount = subUnderwritingManager.myFansCountGetByMonth(3,
                Integer.parseInt(userId), startTime, endTime);

        logger.info("三个等级的粉丝数量为：" + levelGoldMedalCount + "，" + levelDiamondsCount + "，"
                + levelCrownCount);

        /* 每个级别粉丝数找到后，分别计算可得到的月奖励 */
        int levelGoldMedalReward = levelGoldMedalCount >= 10 ? 50 : 0;
        int levelDiamondsReward = levelDiamondsCount >= 10 ? 200 : 0;
        int levelCrownReward = levelCrownCount >= 10 ? 500 : 0;

        logger.info("三个等级可获得奖励为：" + levelGoldMedalReward + "，" + levelDiamondsReward + "，"
                + levelCrownReward);

        // 组装
        JsonReward reward = new JsonReward();
        reward.setGoldMedalCount(levelGoldMedalCount);
        reward.setGoldMedalReward(levelGoldMedalReward);
        reward.setDiamondsCount(levelDiamondsCount);
        reward.setDiamondsReward(levelDiamondsReward);
        reward.setCrownCount(levelCrownCount);
        reward.setCrownReward(levelCrownReward);

        RemoteUtil.response(response, reward, 1, "操作成功");
    }


    /**
     * 查询用户推荐奖励
     *
     * @param request
     * @param response
     * @throws ParseException
     */
    public void recommendRewards(HttpServletRequest request,
                                 HttpServletResponse response) throws ParseException {
        String userId = request.getParameter("userID");
        /*String userToken = request.getParameter("userToken");
        valiTag = accountManager.validate(Integer.parseInt(userId), userToken);
        if (!valiTag) {
            RemoteUtil.response(response, null, -100, "身份异常");
            return;
        }*/

        String pageStr = request.getParameter("page");
        PageUtil page = new PageUtil(Integer.parseInt(pageStr));

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

        List<?> objList2 = subUnderwritingManager.directorPrivilegeOrderIncomesInfoGetByMonth("3",
                Integer.parseInt(userId), page);
        List<JsonRewardAndFans> list2 = new ArrayList<JsonRewardAndFans>();
        for (int i = 0; i < objList2.size(); i++) {
            Object[] obj = (Object[]) objList2.get(i);

            JsonRewardAndFans rewardFans = new JsonRewardAndFans();
            rewardFans.setUserName(obj[0].toString());
            rewardFans.setIcon(obj[1].toString());
            rewardFans.setReward(((BigDecimal) obj[2]).doubleValue());
            rewardFans.setDate(sdf.parse(obj[3].toString()));
            rewardFans.setChannelType(obj[5].toString());
            if (obj[4] != null) {
                rewardFans.setLevelID(new Integer(obj[4].toString()));
            } else {
                rewardFans.setLevelID(1);
            }

            list2.add(rewardFans);
        }

        Collections.sort(list2);

        RemoteUtil.response(response, list2, 1, "操作成功");
    }

    /**
     * 查询用户所有的奖励
     *
     * @param request
     * @param response
     * @throws ParseException
     */
    public void allRwards(HttpServletRequest request,
                          HttpServletResponse response) throws ParseException {
        String userId = request.getParameter("userID");
        /*String userToken = request.getParameter("userToken");
        valiTag = accountManager.validate(Integer.parseInt(userId), userToken);
        if (!valiTag) {
            RemoteUtil.response(response, null, -100, "身份异常");
            return;
        }*/

        String pageStr = request.getParameter("page");
        PageUtil page = new PageUtil(Integer.parseInt(pageStr));

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

        List<?> objList2 = subUnderwritingManager.directorPrivilegeOrderIncomesInfoGetByMonth("0",
                Integer.parseInt(userId), page);
        List<JsonRewardAndFans> list2 = new ArrayList<JsonRewardAndFans>();
        for (int i = 0; i < objList2.size(); i++) {
            Object[] obj = (Object[]) objList2.get(i);

            JsonRewardAndFans rewardFans = new JsonRewardAndFans();
            rewardFans.setUserName(obj[0].toString());
            rewardFans.setIcon(obj[1].toString());
            rewardFans.setReward(((BigDecimal) obj[2]).doubleValue());
            rewardFans.setDate(sdf.parse(obj[3].toString()));
            rewardFans.setChannelType(obj[5].toString());
            if (obj[4] != null) {
                rewardFans.setLevelID(new Integer(obj[4].toString()));
            } else {
                rewardFans.setLevelID(1);
            }

            list2.add(rewardFans);
        }

        //Collections.sort(list2);

        RemoteUtil.response(response, list2, 1, "操作成功");
    }

    public void addLimitQRCode(HttpServletRequest request, HttpServletResponse response) {
        String strUserId = request.getParameter("userId");
        int userId = 0;
        try {
            userId = Integer.parseInt(strUserId);
        } catch (Exception e) {
            RemoteUtil.response(response, null, -1, "参数错误");
            return;
        }

        if (subUnderwritingManager.getLimitQRCodeInfo(userId) != null) {
            RemoteUtil.response(response, null, 0, "该用户已经注册过");
            return;
        } else {
            ClientInfo userInfo = accountManager.getInfo(Integer.parseInt(strUserId));
            if (userInfo == null) {
                RemoteUtil.response(response, null, -2, "用户不存在");
                return;
            }
            String qrCodeImage = QRCodeUtil.getLimitQRCodeName(userInfo, accountManager);
            if (qrCodeImage == null) {
                RemoteUtil.response(response, null, -1, "failure");
                return;
            }
            ThSubUnderwriterQrCodes qrCode = new ThSubUnderwriterQrCodes();
            qrCode.setSubUnderwriterId(userId);
            qrCode.setQrCode(qrCodeImage);
            qrCode.setCreatedAt(new Date());
            qrCode.setQrCodeCreatedAt(new Date());
            if (subUnderwritingManager.saveQRCode(qrCode)) {
                String qrCodePath = Constant.getImageDomain() + File.separator + Path.project
                        + File.separator + "upload" + File.separator + Path.PLATFORM
                        + File.separator + Path.SUBUNDERWRITING + File.separator
                        + qrCodeImage;
                Map<String, String> qrCodeUrl = new HashMap<String, String>();
                qrCodeUrl.put("url", qrCodePath);
                RemoteUtil.response(response, qrCodeUrl, 1, "success");
            } else {
                RemoteUtil.response(response, null, -1, "failure");
            }

        }
    }

    public void getLimitQRCode(HttpServletRequest request, HttpServletResponse response) {
        String strUserId = request.getParameter("userId");
        int userId = Integer.parseInt(strUserId);
        ThSubUnderwriterQrCodes code = subUnderwritingManager.getLimitQRCodeInfo(userId);
        if (code == null) {
            RemoteUtil.response(response, null, 0, "用户不存在");
        } else {
            String qrCodePath = Constant.getImageDomain() + File.separator + Path.project
                    + File.separator + "upload" + File.separator + Path.PLATFORM
                    + File.separator + Path.SUBUNDERWRITING + File.separator
                    + code.getQrCode();
            Map<String, String> qrCodeUrl = new HashMap<String, String>();
            qrCodeUrl.put("url", qrCodePath);
            RemoteUtil.response(response, qrCodeUrl, 1, "success");
        }
    }

    public void getReferrerName(HttpServletRequest request, HttpServletResponse response) {
        int userID = Integer.parseInt(request.getParameter("userID"));
        Object[] referrerList = subUnderwritingManager.referrerInfo(userID);
        RemoteUtil.response(response, referrerList == null ? null : referrerList[1], 1, "success");
    }
}
